<html>
<head><meta charset="utf-8"><title>env vs option env in librustc_attr · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/env.20vs.20option.20env.20in.20librustc_attr.html">env vs option env in librustc_attr</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207277903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/env%20vs%20option%20env%20in%20librustc_attr/near/207277903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matthiaskrgr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/env.20vs.20option.20env.20in.20librustc_attr.html#207277903">(Aug 18 2020 at 15:57)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/2c3dc04ea4071805fbd1b07bd726c1daf03c0384/src/librustc_attr/builtin.rs#L576">https://github.com/rust-lang/rust/blob/2c3dc04ea4071805fbd1b07bd726c1daf03c0384/src/librustc_attr/builtin.rs#L576</a> <br>
Is there a reason why <code>env</code> here?<br>
When building <code>rustfmt</code> (which depends on <code>librustc_attr</code>) via <code>cargo build</code>, I always have to manually pass some value to it to not get a build failure <code>environment variable </code>CFG_RELEASE_CHANNEL<code> not defined</code></p>
<p>Is there a reason to not simply use <code>option_env!(...).unwrap_or_default()</code> so that we end up with a <code>String::new()</code> in case no env var is passed?</p>



<a name="207278706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/env%20vs%20option%20env%20in%20librustc_attr/near/207278706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/env.20vs.20option.20env.20in.20librustc_attr.html#207278706">(Aug 18 2020 at 16:03)</a>:</h4>
<p>I try to discourage option_env! in rustc -- it's really error prone, you can e.g. typo it and it's hard to track down</p>



<a name="207278830"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/env%20vs%20option%20env%20in%20librustc_attr/near/207278830" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/env.20vs.20option.20env.20in.20librustc_attr.html#207278830">(Aug 18 2020 at 16:04)</a>:</h4>
<p>maybe we can e.g. do <code>option_env_if_cfg!(cfg, "FOO")</code> which mandates it without the cfg</p>



<a name="207278879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/env%20vs%20option%20env%20in%20librustc_attr/near/207278879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/env.20vs.20option.20env.20in.20librustc_attr.html#207278879">(Aug 18 2020 at 16:04)</a>:</h4>
<p>then we could have bootstrap set that cfg for in-tree builds but then we have reasonable defaults still</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>